/**
 * 初始化详情对话框
 */
var EvalDicEntryInfoDlg = {
    EvalDicEntryInfoData : {},
    mutiString: '',		//拼接字符串内容(拼接字典条目)
    validateFields: {
        description: {
            validators: {
                notEmpty: {
                    message: '描述不能为空'
                }
            }
        },
    	code: {
            validators: {
                notEmpty: {
                    message: '代码不能为空'
                }
            }
        },
        score: {
            validators: {
                notEmpty: {
                    message: '分数不能为空'
                }
            }
        }
    }
};

/**
 * 清除数据
 */
EvalDicEntryInfoDlg.clearData = function() {
    this.EvalDicEntryInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
EvalDicEntryInfoDlg.set = function(key, val) {
    this.EvalDicEntryInfoData[key] = (typeof val == "undefined") ? $("[id=" + key+"]").val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
EvalDicEntryInfoDlg.get = function(key) {
    return $("[name=" + key+"]").val();
}

/**
 * 关闭此对话框
 */
EvalDicEntryInfoDlg.close = function() {
    parent.layer.close(parent.layer.getFrameIndex(window.name)); //先得到当前iframe层的索引,再执行关闭   
}

/**
 * 清除为空的item Dom
 */
EvalDicEntryInfoDlg.clearNullDom = function(){
    $("[name='dicLevelInfo_levelName']").each(function(){
        var name = $(this).val();
        if(name == ''){
            $(this).parent().parent().remove();
        }
    });
};

/**
 * 收集数据
 */
EvalDicEntryInfoDlg.collectData = function() {
    this.set('id');
    this.set('itemId');
	this.set('code');
	this.set('description');
	this.set('score');
	this.set('type');
	this.set('formula');
	this.set('mutexFlag');
	this.set('relationFlag');
};

/**
 * 验证数据是否为空
 */
EvalDicEntryInfoDlg.validate = function () {
    $('#EvalDicEntryInfoForm').data("bootstrapValidator").resetForm();
    $('#EvalDicEntryInfoForm').bootstrapValidator('validate');
    return $("#EvalDicEntryInfoForm").data('bootstrapValidator').isValid();
};

/**
 * 提交添加
 */
EvalDicEntryInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();
    
    if (!this.validate()) {
        return;
    }

    //提交信息
    var ajax = new $ax(Sys.backendPath + "/sdc/evaldicentry/add", function(data){
        Sys.success("添加成功!");
        window.parent.EvalDicEntry.table.refresh();
        EvalDicEntryInfoDlg.close();
    },function(data){
        Sys.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.EvalDicEntryInfoData);
    ajax.set('levelInfos',this.mutiString);
    ajax.start();
}

/**
 * 提交修改
 */
EvalDicEntryInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }

    //提交信息
    var ajax = new $ax(Sys.backendPath + "/sdc/evaldicentry/update", function(data){
        Sys.success("修改成功!");
        window.parent.EvalDicEntry.table.refresh();
        EvalDicEntryInfoDlg.close();
    },function(data){
        Sys.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.EvalDicEntryInfoData);
    ajax.set('levelInfos',this.mutiString);
    ajax.start();
}

$(function() {
    Sys.initValidator("EvalDicEntryInfoForm", EvalDicEntryInfoDlg.validateFields);
});
